var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    open: false,
    imageFlag: true,
    isPlay: false,
    src: "",
    incame:0,
    videos: ["http://172.16.117.63/group1/M00/00/06/rBB1P1r9IwqADx__AAuT7px5WLY183.mp4", "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400", "http://172.16.117.63:80/group1/M00/00/06/rBB1P1r9JD6AJu-qAB3G37abQzA151.mp4"],
    id:0,
    timeFlag: false
  },
  click: function(){
    wx.showToast({
      title: '点击到了' + app.globalData.time,
    })
  },
  pause: function(){
      this.videoContext.pause();
      this.setData({
        isPlay: true
      })
  },
  play: function(){
    this.videoContext.play();
    this.setData({
      isPlay: false
    })
  },
  openText: function(){
    if(!this.data.open){
      this.setData({
        open: true
      })
    }else{
      this.setData({
        open: false
      })
    }
    
  },
  update: function(e){
    // this.setData({
    //   imageFlag: false
    // })
    // console.log(e.detail)
    app.globalData.time = e.detail.currentTime;
    if (e.detail.currentTime>0.1){
      this.setData({
      imageFlag: false
    })
    }
    if(!this.data.timeFlag){
      console.log(11111)
      if (e.detail.duration - e.detail.currentTime <3) {
        console.log(22222)
        wx.showToast({
          title: '该做题了',
        })
        this.setData({
          timeFlag: true
        })
        setTimeout(()=>{
          this.setData({
            timeFlag: false
          })
        }, 3000)
      }
    }
    
  },
  end: function(){
    this.setData({
      timeFlag: false
    })
    console.log("end")
  },
  playstart: function(e){
    // this.setData({
    //   imageFlag: false
    // })
    // console.log(e)
    // this.data.incame++;
    // if (this.data.incame == 2) {
    //   this.videoContext.pause();
    // }
    // setTimeout(()=>{
      // this.setData({
      //   imageFlag: false
      // })
    // }, 100)
    
    // if (this.data.incame==1){
    //   this.videoContext.play();
    // }
  
   
    
  },
  work: function(){
    wx.navigateTo({
      url: '../problem/problem',
    })
  },
  last: function(){

    if(this.data.id==0){
      wx.showToast({
        title: '已经是第一条',
      })
    }else{
      wx.redirectTo({
        url: '../video/video?id=' + (parseInt(this.data.id) - 1),
      })
    }
    
  },
  next: function(){

    if(this.data.id==2){
      wx.showToast({
        title: '已经是第一条',
      })
    }else{
      wx.redirectTo({
        url: '../video/video?id=' + (parseInt(this.data.id) + 1),
      })
    }
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id)
    this.setData({
      id: options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo');
    
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.redirectTo({
      url: '../video/video',
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})